#ifndef C_ALGORITHM_BIN_THREAD_TREE_H
#define C_ALGORITHM_BIN_THREAD_TREE_H

#include <stdbool.h>
#include <stddef.h>

// 不完整类型, 隐藏树结构定义
typedef struct bi_tree_t *bitree;

// 不完整类型, 树节点指针类型, 隐藏节点定义
typedef struct bi_Node_t *bi_node;

// 函数类型,获得结点的键值
typedef const void *get_key_func_t(const void *data);

// 排序比较函数
typedef int cmp_func_t(const void *key1, const void *key2);

bitree bit_tree_create(cmp_func_t *cmp, get_key_func_t *getKeyfunc);

void bit_tree_clear(bitree btree);

void bit_tree_destory(bitree btree);

bool bit_tree_insert(bitree btree, const void *data, size_t size);

bool bit_tree_delete(bitree btree, const void *key);

const void *bit_tree_search(bitree btree, const void *key);

int bit_tree_in_order(bitree btree, bool (*action)(void *data));

int bit_tree_pre_order(bitree btree, bool (*action)(void *data));

int bit_tree_post_order(bitree btree, bool (*action)(void *data));

// 线索化二叉树
void bit_tree_thread(bitree btree);

// 中序线索后继遍历
void bit_tree_in_order_thread(bitree btree, bool (*action)(void *data));

// 中序线索前驱遍历
void bit_tree_rev_in_order_thread(bitree btree, bool (*action)(void *data));

#endif